<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.*, java.sql.*, connection.*"%>
<%
/* 
<td >
<input type="text" name="name" value=""></td>
<td ><input type="text" name="latitude" value=""></td>
		  <td ><input type="text" name="longitude" value=""></td>
		  <td ><input type="text" name="description" value=""></td>
		  */
		  Connection conn = new DbConnection().getConn();
		  String name = request.getParameter("name");
		  String latitude = request.getParameter("latitude");
		  String longitude = request.getParameter("longitude");
		  String description = request.getParameter("description");
		  String creatorName = (String)session.getAttribute("username");
		  
		  System.out.println("name:"+name+" lat:"+latitude+" long:"+longitude+" description:"+description+" creator:"+ creatorName);
		  /*
		  ,Version number	default 0
	,Name		VARCHAR2(40)
	,Description	VARCHAR2(256)
	,CreateTime	DATE
	,Latitude	VARCHAR2(40)
	,Longitude	VARCHAR2(40)
	,CreatorName	VARCHAR2(40)
		  */
		  String sql = "INSERT INTO Poll(Version, Name, Description, Latitude, Longitude, CreatorName) "+
		  "VALUES(0, '"+name+"','"+description+"', "+latitude+", "+longitude+", '"+creatorName+"')";
		  
		  try{
		  	PreparedStatement ps = conn.prepareStatement(sql);
		  	ps.executeQuery();
			
		  	response.sendRedirect("newPoll.jsp?fail=false&pollname="+name);
		  }catch(SQLException e){
			  System.out.println(e);
			  response.sendRedirect("newPoll.jsp?fail=true");
		  }
%>